<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>简单轮播图</title>
    <style>
        #imgs{
            width: 200px;
            height: 200px;
        }
        div{
            width: 200px;
            height: 200px;
            text-align: center;
        }
        div input{
            width: 70px;
            height: 70px;
            margin: 0 10px;
            display: inline-block;      
        }
    </style>
    <script>
        window.onload = function(){
            var img = document.getElementById('imgs');
            var prev = document.getElementById('prev');
            var next = document.getElementById('next');
            var maxIndex = 9;
            var minIndex = 1;
            var index = minIndex;
            
            prev.onclick = function(){
                if(minIndex === index){
                    index = maxIndex ;
                }else{
                    index--;
                } 
                img.setAttribute('src','img/op' + index + '.jpg')
            }
            next.onclick = function(){
                if(maxIndex === index){
                    index = minIndex ;
                }else{
                    index++;
                } 
                img.setAttribute('src','img/op' + index + '.jpg')
            }

        }   
    </script>
</head>
<body>
    <img id="imgs" src="img/op1.jpg" alt="海贼王">
    <div>
        <input id="prev" type="button" value="上一张">
        <input id="next" type="button" value="下一张">
    </div>
</body>
</html>